import { Component, OnInit , ChangeDetectorRef } from '@angular/core';
import { CommonService } from '../../service/common.service'


@Component({
  selector: 'app-news',
  templateUrl: './news.page.html',
  styleUrls: ['./news.page.scss'],
})
export class NewsPage implements OnInit {

  public list:any[] = [];
  public zixunimg:string;
  public flag:boolean = false;
  public page:number = 1;
  public limit:number = 10;
  
  constructor(private common:CommonService,private changeDetectorRef:ChangeDetectorRef) {
    
  }


  ngOnInit() {
    this.Information()
    this.zixun()
  }

  //资讯列表  
  Information(){  
    var api = '/tbr/getInformationList'
    var params = {
        page:this.page,
        limit:this.limit
    }
    console.log(this.page)
    this.common.post(api,params,false).then((res:any)=>{
      if(res.code == 200){
        for(var i=0;i<res.data.records.length;i++){
          this.list.push(res.data.records[i])
        }
        if(res.data.records.length < this.limit){
          this.flag = true
        }
      }
    })
  }

  // 上拉更新
  loadData(event) {
    if (this.flag == true) {
      event.target.disabled = true;
      return
    }
    setTimeout(() => {
      this.page += 1;
      this.Information()
      event.target.complete();
    }, 700);
  }


  // 1 首页 2商城 3咨询
  zixun(){  
    var api = '/tbr/getBanners'
    var params = {type:3}
    this.common.post(api,params,false).then((res:any)=>{
      console.log(res)
      if(res.code == 200){
        this.zixunimg = res.data[0].imagePath
      }
    })
  }

}
